package com.situ.day250116;

import com.situ.day250114.Student;
import org.junit.Test;

import java.util.Arrays;

public class StringDemo {
    @Test
    public void test() {
        String str1 = "abc";
        String str2 = new String("abc");
        String str3 = "abc";
        System.out.println(str1 == str2);//false
        System.out.println(str1 == str3);//true
        System.out.println(str1.equals(str2));//true
        System.out.println(str1.equals(str3));//true
    }
    @Test
    public void test2() {
        Student[] students = new Student[10];
        String str1 = "abc boyinxiyin";
        System.out.println(str1.length());//14
        char[] chars = str1.toCharArray();
        char ch = chars[0];//a
        System.out.println(ch);
        System.out.println(str1.indexOf("i"));//7
        System.out.println(str1.lastIndexOf("i"));//12
        System.out.println(str1.indexOf("i",4));//7
        System.out.println(str1.indexOf("i",9));//10
    }
    @Test
    public void test3() {
        String str1 = "java";
        String str2 = "Java";
        System.out.println(str1.equals(str2));//false
        System.out.println(str1.equalsIgnoreCase(str2));//true

        String str = "java AndroidA";
        System.out.println(str.contains("And"));//true  是否包含
        System.out.println(str.startsWith("java"));//true
        //offset:偏移
        System.out.println(str.startsWith("And", 5));//true
        System.out.println(str.endsWith("oidA"));//true 是否以这个字母结尾
        System.out.println(str.isEmpty());//false
        //"":空字符串，也是一个对象   ' '
        System.out.println("".isEmpty());//true  字符串是否为空
        char ch = ' ';
    }
    @Test
    public void test44() {
        // ""
        //String str = "java And";
        char[] array = {'j', 'a', 'v', 'a', ' ', 'A', 'n', 'd'};
        String str = new String(array);
        System.out.println(str);//java And
        char[] chars = str.toCharArray();
        System.out.println(chars);
        //Arrays：操作数组的工具类
        System.out.println(Arrays.toString(chars));
        //[j, a, v, a,  , A, n, d]
    }
    @Test
    public void test5() {
        Integer integer1 = Integer.valueOf(1);
        Integer integer2 = Integer.valueOf(2);
        int i = integer1.intValue();
        int j = integer2;//自动装箱
        Integer integer3 = 3;
        int a = integer1 +3;
        System.out.println(i);
        System.out.println(j);
        System.out.println(a);
    }
    @Test
    public void test6() {
        String str1 = "15";
        int i = Integer.parseInt(str1);//把字符串转换成整数类型
        double d = Double.parseDouble(str1);
        boolean b = Boolean.parseBoolean(str1);
        String str2 = "KjhhJ";
        System.out.println(str2.toLowerCase());
        System.out.println(str2.toUpperCase());
    }
}
